<template>
  <div class="v-container">
    <div>
      <div class="banner_img">
        <img src="@/assets/images/main_banner.jpg" width="100%">
        <div class="pos_btn"  @click="pageTo('order')">
          <p>订单中心</p>
        </div>
      </div>
      <div class="threeB">
        <div class="tB_wrap">
          <div class="rel  g-clearfix">
            <div class="tB_left"  @click="pageTo('equity')">
              <div class="padd">
                <img src="@/assets/images/inde_img01.png" width="100%">
              </div>
            </div>
            <div class="tB_right">
              <div class="padd">
                <div class="rel  g-clearfix">
                  <div class="img02"  @click="pageTo('no')">
                    <img src="@/assets/images/inde_img02.png" width="100%">
                  </div>
                  <div class="img03"  @click="pageTo('no')">
                    <img src="@/assets/images/inde_img03.png" width="100%">
                  </div>
                </div>
              </div>
            </div>
          </div>
          
        </div>
      </div>
      <div class="kF"   @click="tel()">
          <img src="@/assets/images/index_kf.png" width="50">
              
      </div>
    </div>
  </div>
</template>

<script>

import { Toast } from 'mint-ui';
import { Resource } from '@/services/resource';
import LocalStorage from '@/services/storage';
import { MessageBox } from 'mint-ui';

export default {
  name: "mainpage",
  props: {
    title: {
      type: String,
      default: "标题"
      
    }
  },
  mounted() {
    let that=this;
    let loginDate=this.getUrlParam("data");
    // let loginDate="b1eL91Cm9uML9vSOj7qQTXDixXXtTKv7j1o7zCy5N+9LMObZnM43BjRDarw2Rx7G";
    if(loginDate){
      var _new_loginDate=loginDate.replace(/\ |%2B/g, '+')
      LocalStorage.setLocalStorage(
        "loginDate",
        _new_loginDate,
        90 * 24 * 60 * 60 * 1000
      );
    }
    let isWx=that.is_weixn();
    let _code=sessionStorage.code;
    if(isWx){
      let code = that.getUrlParam("code");
      if(code == null || code ===''){
        var local = window.location.href;
        var _local=local.split('#')[0];
          window.location.href = "http://sd.auto1768.com/ShengDaAutoUnionPay/gaindAuthoriCode?redirect_uri="+encodeURIComponent(_local);
      }else{
        sessionStorage.code=code;
      }
    }


    this.loginFun();
  },
  created() {
  
  },
  data() {
    return {
      
      
    };
  },
  methods:{
    tel(){
      window.location.href = "tel:4008881768";
    },
    loginFun(){
      Resource.login
      .post({}, { data: LocalStorage.getLocalStorage('loginDate')})
      .then(res => {
        console.log(res);
        if (res.head.resultCode == "000000") {
          let token = res.head.token;

          LocalStorage.setLocalStorage(
            "token",
            token,
            59 * 60 * 1000
          );
          this.$store.dispatch("login", token);

        } else {
          // Toast({
          //   message: res.head.resultMsg,
          //   position: 'middle'
          // });
          MessageBox.alert(res.head.resultMsg,'温馨提示').then(action => {
             
            });
        }
      });
    },
    // 跳转页面
    pageTo(name) {
      console.log(name);
      if(name=='no'){
        MessageBox.alert('服务暂未开启，敬请期待~','温馨提示');
      }else{
        this.$router.push(name);
      }
      
    },
    // 返回上一页
    goBack(){
      this.$router.go(-1);
    },
    is_weixn(){ 
      var ua = navigator.userAgent.toLowerCase(); 
      return ua.match(/MicroMessenger/i)=='micromessenger';
    },
    getUrlParam(name){
      var reg = new RegExp('(^|&)'+name+'=([^&]*)(&|$)');
      var r = window.location.search.substr(1).match(reg);
      if(r!=null){
        return unescape(r[2]);
      }
      return null;
    },
    
    
  }
};
</script>

<style lang="less" scoped>
@import url("./style.less");

</style>
